package com.liao.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liao.bean.ServerCount;
import com.liao.bean.result.Code;
import com.liao.bean.result.Msg;
import com.liao.bean.result.PageResult;
import com.liao.dao.ServerCountDao;
import com.liao.service.ServerCountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ServerCountServiceImpl implements ServerCountService {

    @Autowired
    private ServerCountDao serverCountDao;

    @Override
    public PageResult<ServerCount> queryServerCountListByPage(Integer currentPage, Integer pageSize, String scid) throws Exception {

        PageHelper.startPage(currentPage,pageSize);

       List<ServerCount> countList= serverCountDao.selectServerCountListByPage(scid);

        PageInfo<ServerCount> pageInfo=new PageInfo<>(countList);


        return new PageResult<ServerCount>(0, Msg.MODULE_QUERY_SUCCESS,pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public void deleteServerCountById(String scid) throws Exception {

        serverCountDao.deleteServerCountById(scid);
    }

    @Override
    public void addServerCount(String scid, String orderId, String orderMoney, String serverMoney) throws Exception {

        ServerCount serverCount=new ServerCount();
        serverCount.setScid(scid);
        serverCount.setOrderId(orderId);
        serverCount.setOrderMoney(orderMoney);
        serverCount.setServerMoney(serverMoney);

        serverCountDao.addServerCount(serverCount);


    }

    @Override
    public void updateServerCount(String scid, String orderId, String orderMoney, String serverMoney) throws Exception {

        ServerCount serverCount=new ServerCount();
        serverCount.setScid(scid);
        serverCount.setOrderId(orderId);
        serverCount.setOrderMoney(orderMoney);
        serverCount.setServerMoney(serverMoney);

        serverCountDao.updateServerCount(serverCount);


    }
}
